package cn.yl.caner.service;

import java.sql.SQLException;
import cn.yl.caner.dao.LoginDao;
import cn.yl.caner.domain.LoginData;
import cn.yl.caner.utils.MyDataSourceUtils;

public class LoginService {
	
	public LoginData loginAccount(LoginData logindata) {
		//
		 LoginData loginAccount = null;
		 LoginDao logindao = new LoginDao();
			try {
				//获取连接，并设置事务
				MyDataSourceUtils.start();
				loginAccount = logindao.loginAccount(logindata);
				return loginAccount;
			} catch (SQLException e) {
				try {
					//失败回滚
					MyDataSourceUtils.rollback();
				} catch (SQLException e1) {
					System.out.println("事物回滚失败");
				}
				System.out.println("事物出现错误！");
			}finally {
				try {
					//提交事务
					MyDataSourceUtils.commit();
				} catch (SQLException e) {
					System.out.println("事物提交失败！");
				}
			}
		return loginAccount;
	}
}